package com.sise.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sise.bean.BackStageOrderDetailBean;
import com.sise.entity.OrderDetail;
import com.sise.entity.ProductInfo;
import com.sise.mapper.OrderDetailMapper;
import com.sise.mapper.ProductInfoMapper;
import com.sise.service.IOrderDetailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zj
 */
@Service
public class OrderDetailServiceImpl extends ServiceImpl<OrderDetailMapper, OrderDetail> implements IOrderDetailService {

    @Resource
    private OrderDetailMapper orderDetailMapper;

    @Resource
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<BackStageOrderDetailBean> getOrderDetailByOrderId(String orderId) {
        QueryWrapper<OrderDetail> orderDetailQueryWrapper = new QueryWrapper<>();
        orderDetailQueryWrapper.lambda().eq(OrderDetail::getOrderId, orderId);
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(orderDetailQueryWrapper);
        List<BackStageOrderDetailBean> backStageOrderDetailBeanList = new ArrayList<>();
        for (OrderDetail orderDetail : orderDetailList) {
            ProductInfo productInfo = productInfoMapper.selectById(orderDetail.getProductId());
            BackStageOrderDetailBean backStageOrderDetailBean = new BackStageOrderDetailBean();
            backStageOrderDetailBean.setProductName(productInfo.getProductName());
            backStageOrderDetailBean.setProductBuyNumber(orderDetail.getProductBuyNumber());
            backStageOrderDetailBean.setProductPrice(orderDetail.getProductBuyPrice());
            backStageOrderDetailBeanList.add(backStageOrderDetailBean);
        }
        return backStageOrderDetailBeanList;
    }
}
